package com.zwh.autoconfigure.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * 显示声明直连交换机，routing key值相等匹配
 * @author monkey
 * @date 2020/11/3 10:38
 **/
//@EnableRabbit
@Configuration
public class DirectExchangeConfig {
    public static final String SECONDKILL_EXCHANGE = "myDirect";
    public static final String SECONDKILL_QUEUE = "secondKill.queue";
    @Bean
    public DirectExchange directExchange(){
        DirectExchange directExchange=new DirectExchange(SECONDKILL_EXCHANGE);
        return directExchange;
    }

    @Bean
    public Queue directQueue1() {
        return new Queue(SECONDKILL_QUEUE);
    }

    //3个binding将交换机和相应队列连起来
    @Bean
    public Binding bindingSecondKill(){
        Binding binding= BindingBuilder.bind(directQueue1()).to(directExchange()).with(SECONDKILL_QUEUE);
        return binding;
    }
}
